package com.example.administrator.compileapp.activity;

import android.database.DatabaseUtils;
import android.databinding.DataBindingUtil;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import com.example.administrator.compileapp.BR;
import com.example.administrator.compileapp.R;
import com.example.administrator.compileapp.bean.OtherStartEntity;
import com.example.administrator.compileapp.callback.OnDeleteDataListener;
import com.example.administrator.compileapp.databinding.ActivityOtherStartListBinding;
import com.example.administrator.compileapp.drawer.FunctionIntrodutionActivity;
import com.example.administrator.compileapp.until.CommentRecyclerAdapter;

import java.util.ArrayList;
import java.util.List;

import cn.sharesdk.onekeyshare.OnekeyShare;

public class OtherStartListActivity extends AppCompatActivity implements OnDeleteDataListener {
   private ActivityOtherStartListBinding binding;
    private CommentRecyclerAdapter adapter;
    private  List<OtherStartEntity>  list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding= DataBindingUtil.setContentView(this,R.layout.activity_other_start_list);
        aboutRecycler();
        binding.otherStartListBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void aboutRecycler() {
         list = new ArrayList<>();
        OtherStartEntity wangyiyun = new OtherStartEntity("网易云","http://study.163.com/");
        OtherStartEntity qida = new OtherStartEntity("企大课堂","http://yun.qida.com/");
        OtherStartEntity baidu = new OtherStartEntity("百度课堂","https://chuanke.baidu.com/");
        OtherStartEntity zhihui = new OtherStartEntity("智慧树在线教育","http://www.zhihuishu.com/");
        list.add(wangyiyun);
        list.add(qida);
        list.add(baidu);
        list.add(zhihui);
        adapter = new CommentRecyclerAdapter<>(this,list,R.layout.other_start_item, BR.otherStartEntity);
        adapter.setListener(this);
        binding.recycler.setAdapter(adapter);
    }

    @Override
    public void OnDeleteData(int position, String name) {
        adapter.remove(position);
    }

    @Override
    public void onShareData(boolean isShareData,int positon) {
        if(isShareData==true){
          showShare(list.get(positon).getWebName(),list.get(positon).getWebUrl());
        }
    }
    public void showShare(String title,String url) {
        OnekeyShare oks = new OnekeyShare();
        //关闭sso授权
        oks.disableSSOWhenAuthorize();
        // title标题，印象笔记、邮箱、信息、微信、人人网、QQ和QQ空间使用
        oks.setTitle(title);
        // titleUrl是标题的网络链接，仅在Linked-in,QQ和QQ空间使用
        //http://sharesdk.cn
        oks.setTitleUrl(url);
        // text是分享文本，所有平台都需要这个字段
        oks.setText("我是分享文本");
        //分享网络图片，新浪微博分享网络图片需要通过审核后申请高级写入接口，否则请注释掉测试新浪微博
        oks.setImageUrl("http://f1.sharesdk.cn/imgs/2014/02/26/owWpLZo_638x960.jpg");
        // imagePath是图片的本地路径，Linked-In以外的平台都支持此参数
        //oks.setImagePath("/sdcard/test.jpg");//确保SDcard下面存在此张图片
        // url仅在微信（包括好友和朋友圈）中使用
        oks.setUrl("http://sharesdk.cn");
        // comment是我对这条分享的评论，仅在人人网和QQ空间使用
        oks.setComment("我是测试评论文本");
        // site是分享此内容的网站名称，仅在QQ空间使用
        oks.setSite("ShareSDK");
        // siteUrl是分享此内容的网站地址，仅在QQ空间使用
        oks.setSiteUrl("http://sharesdk.cn");

// 启动分享GUI
        oks.show(this);
    }
}
